package lib.ui.button{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class BaseButton extends Sprite{
		
		private var _ableSkin:Bitmap;
		private var _selectSkin:Bitmap;
		private var _disableSkin:Bitmap;
		private var _overSkin:Bitmap;
		private var _skin:Bitmap;
		
		public function BaseButton(ableSkin:Bitmap,selectSkin:Bitmap,disableSkin:Bitmap,overSkin:Bitmap){
			_ableSkin = ableSkin;
			_selectSkin = selectSkin;
			_disableSkin = disableSkin;
			_overSkin = overSkin;
			_skin = new Bitmap(new BitmapData(ableSkin.width,ableSkin.height));
			_skin.bitmapData = ableSkin.bitmapData;
			config();
			this.mouseChildren = false;
			this.addChild(_skin);
		}
		
		private function config():void{
			this.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
			this.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
			this.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
			this.addEventListener(MouseEvent.MOUSE_UP, onRollOver);
		}
		
		private function onRollOver(e:MouseEvent):void {
			_skin.bitmapData = _overSkin.bitmapData;
		}
		
		private function onRollOut(e:MouseEvent):void {
			_skin.bitmapData = _ableSkin.bitmapData;
		}
		
		private function onClick(e:MouseEvent):void{
			_skin.bitmapData = _selectSkin.bitmapData;
		}
	}
}